package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig_Header {


    public static final String Exchange_Header_1 = "Exchange_Header_1";

    public static final String Queue_Header_1 = "Queue_Header_1";
    public static final String Queue_Header_2 = "Queue_Header_2";


    @Bean(Exchange_Header_1)
    public HeadersExchange exchange_Topic_1(){
        return ExchangeBuilder.headersExchange(Exchange_Header_1).build();
    }

    @Bean(Queue_Header_1)
    public Queue queue_Topic_1(){
        return QueueBuilder.durable(Queue_Header_1).build();
    }

    @Bean(Queue_Header_2)
    public Queue queue_Topic_2(){
        return QueueBuilder.durable(Queue_Header_2).build();
    }


    @Bean
    public Binding binding_header_1(
            @Qualifier(Queue_Header_1) Queue queue,
            @Qualifier(Exchange_Header_1) HeadersExchange exchange){
        Map map = new HashMap<>();
        map.put("Inform1","email");
        map.put("Inform2","sms");
        return BindingBuilder.bind(queue).to(exchange).whereAll(map).match();
    }

    @Bean
    public Binding binding_header_2(
            @Qualifier(Queue_Header_2) Queue queue,
            @Qualifier(Exchange_Header_1) HeadersExchange exchange){
        Map map = new HashMap<>();
        map.put("Inform1","email");
        map.put("Inform3","qq");
        return BindingBuilder.bind(queue).to(exchange).whereAny(map).match();
    }
}
